Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming
Inheritance and the class hierarchy
One of the great powers of object-oriented programming is inheritance, which facilitates code reuse and polymorphism. The new
CLASSconstruct supports single inheritance of classes. This inheritance allows a class (subclass) to extend another class (its super class). The subclass class inherits all the non-private data members and methods of the super class so that they appear as if they are part of the subclass. The super class itself might have extended its own super class, forming a class hierarchy. Through this chain of inheritance a subclass inherits behavior from all of its super classes. The root class of a hierarchy is the class that does not inherit from any other class. In Progress, the root class of all classes is the built-in classProgress.Lang.Object.When a subclass is instantiated, the constructor for each class in its class hierarchy is executed as part of the instantiation process. Progress first invokes the constructor in the bottom-most object subclass. The first action of this subclass’s constructor must be to invoke the super class's constructor, whether implicitly or (especially if parameters must be passed) explicitly. This super class constructor, in turn, invokes its own super class constructor. This chain of super class constructor invocation continues to the root class. When the root class's constructor is invoked, it executes to completion. Execution then returns to its caller, its immediate subclass, so that the subclass constructor can complete. This sequence continues until the constructor in the bottom-most subclass completes. In this way, although instantiation of a class hierarchy always starts at the bottom, the object representing this hierarchy is constructed from the top of its inheritance tree down.
Polymorphism supports the ability for a super class object reference to invoke a subclass's implementation at run time. The super class defines the method and a subclass overrides the method with its own behavior. For an instance of a subclass, which is accessed by an object reference to the super class, a call to a super class method that the subclass has overridden actually invokes the subclass's version of that method. The same is true within a class hierarchy. A direct call within a class to an overridden method from anywhere within the hierarchy always invokes the method in the bottom-most subclass that has an overriding method definition.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |